package com.hosever.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import com.hosever.core.AbstractModel;
/**
 * 标签
 * @author Sever
 *
 */
@Entity
@Table(name="tbl_tag")
public class Tag extends AbstractModel {
	private static final long serialVersionUID = 1L;
	/**
	 * 名称
	 */
	private String name;
	/**
	 * 子标签
	 */
	@OneToMany(targetEntity = Tag.class,cascade=CascadeType.ALL,fetch=FetchType.EAGER)
	@JoinColumn(name="parentTagId",updatable=false) 
	private List<Tag> childTags = new ArrayList<Tag>();
	/**
	 * 父标签
	 */
	@ManyToOne(targetEntity = Tag.class)
	@JoinColumn(name="parentTagId",updatable=false) 
	private Tag parentTag;
	/**
	 * 文章所属
	 */
	@ManyToMany(mappedBy = "tags") 
	@OrderBy("updateDate desc")
	private List<Article> articles = new ArrayList<Article>();
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public List<Tag> getChildTags() {
		return childTags;
	}
	public void setChildTags(List<Tag> childTags) {
		this.childTags = childTags;
	}
	public Tag getParentTag() {
		return parentTag;
	}
	public void setParentTag(Tag parentTag) {
		this.parentTag = parentTag;
	}
	public List<Article> getArticles() {
		return articles;
	}
	public void setArticles(List<Article> articles) {
		this.articles = articles;
	}
	
}
